var app = getApp();

Page({
    data: {
        is_show_share: !1,
        _is_load: !0,
        is_akey: !1,
        bjid: ""
    },
    onLoad: function(a) {
        var i = this;
        app.util.footer(this), app.util.getUserInfo(function(a) {
            var t = this;
            i.setData({
                userInfo: a,
                avatar: a.memberInfo.avatar,
                nickname: a.memberInfo.nickname
            }), i.data.userInfo.memberInfo.nickname || (app.globalData.userInfo ? this.setData({
                userInfo2: app.globalData.userInfo,
                avatar: app.globalData.userInfo.avatarUrl,
                hasUserInfo: !0
            }) : this.data.canIUse ? app.userInfoReadyCallback = function(a) {
                t.setData({
                    userInfo2: a.userInfo,
                    avatar: a.userInfo.avatarUrl,
                    hasUserInfo: !0
                });
            } : wx.getUserInfo({
                success: function(a) {
                    app.globalData.userInfo = a.userInfo, t.setData({
                        userInfo2: a.userInfo,
                        avatar: a.userInfo.avatarUrl,
                        hasUserInfo: !0
                    });
                }
            })), app.util.request({
                url: "entry/wxapp/Setup",
                data: {
                    m: "bbyscm_card"
                },
                success: function(a) {
                    i.setData({
                        setup: a.data.data,
                        audio: a.data.data.audio
                    });
                }
            }), app.util.request({
                url: "entry/wxapp/VideoSetup",
                data: {
                    m: "bbyscm_card"
                },
                success: function(a) {
                    i.setData({
                        videosetup: a.data.data
                    });
                }
            }), app.util.request({
                url: "entry/wxapp/GetGun",
                data: {
                    m: "bbyscm_card"
                },
                success: function(a) {
                    i.setData({
                        guns: a.data.data
                    });
                }
            }), app.util.request({
                url: "entry/wxapp/GetCard",
                data: {
                    m: "bbyscm_card"
                },
                success: function(a) {
                    if (0 == a.data.errno) if (a.data.data) {
                        if (1 == a.data.data.harass) {
                            var t = a.data.data.mobile2.substr(0, 4) + "*****" + a.data.data.mobile2.substr(9), e = a.data.data.mobile.substr(0, 4) + "*****" + a.data.data.mobile.substr(8);
                            if (1 == a.data.data.sex) var d = a.data.data.cardname.substr(0, 1) + "先生" + a.data.data.cardname.substr(7); else if (0 == a.data.data.sex) d = a.data.data.cardname.substr(0, 1) + "女士" + a.data.data.cardname.substr(7); else d = a.data.data.cardname.substr(0, 1) + a.data.data.job + a.data.data.cardname.substr(7);
                        } else t = a.data.data.mobile2, e = a.data.data.mobile, d = a.data.data.cardname;
                        0 == a.data.data.akey ? (i.setData({
                            card_info: a.data.data,
                            cardid: a.data.data.id,
                            bjid: a.data.data.bj,
                            industry: a.data.data.industry,
                            cardname: d,
                            mobile: e,
                            mobile2: t,
                            card_template: a.data.data.card_template,
                            imagp: a.data.data.imagp,
                            exchange: a.data.data.exchange,
                            _is_load: !1
                        }), 0 == a.data.data.fenxiang && wx.hideShareMenu()) : (i.setData({
                            card_info: a.data.data,
                            cardid: a.data.data.id,
                            bjid: a.data.data.bj,
                            industry: a.data.data.industry,
                            cardname: d,
                            mobile: e,
                            mobile2: t,
                            card_template: a.data.data.card_template,
                            imagp: a.data.data.imagp,
                            exchange: a.data.data.exchange,
                            _is_load: !1,
                            is_akey: !0
                        }), wx.hideShareMenu());
                    } else i.setData({
                        _is_load: !1
                    });
                }
            });
        });
    },
    onReady: function() {},
    onShow: function() {
        this.onPullDownRef(!0);
    },
    onPullDownRef: function() {
        var r = this;
        app.util.request({
            url: "entry/wxapp/GetCard",
            data: {
                m: "bbyscm_card"
            },
            success: function(a) {
                if (0 == a.data.errno) if (a.data.data) {
                    if (1 == a.data.data.harass) {
                        var t = a.data.data.mobile2.substr(0, 4) + "*****" + a.data.data.mobile2.substr(9), e = a.data.data.mobile.substr(0, 4) + "*****" + a.data.data.mobile.substr(8);
                        if (1 == a.data.data.sex) var d = a.data.data.cardname.substr(0, 1) + "先生" + a.data.data.cardname.substr(7); else if (0 == a.data.data.sex) d = a.data.data.cardname.substr(0, 1) + "女士" + a.data.data.cardname.substr(7); else d = a.data.data.cardname.substr(0, 1) + a.data.data.job + a.data.data.cardname.substr(7);
                    } else t = a.data.data.mobile2, e = a.data.data.mobile, d = a.data.data.cardname;
                    if (0 == a.data.data.akey ? (r.setData({
                        card_info: a.data.data,
                        cardid: a.data.data.id,
                        bjid: a.data.data.bj,
                        industry: a.data.data.industry,
                        cardname: d,
                        mobile: e,
                        mobile2: t,
                        card_template: a.data.data.card_template,
                        imagp: a.data.data.imagp,
                        exchange: a.data.data.exchange,
                        _is_load: !1
                    }), 0 == a.data.data.fenxiang && wx.hideShareMenu()) : r.setData({
                        card_info: a.data.data,
                        cardid: a.data.data.id,
                        bjid: a.data.data.bj,
                        industry: a.data.data.industry,
                        cardname: d,
                        mobile: e,
                        mobile2: t,
                        card_template: a.data.data.card_template,
                        imagp: a.data.data.imagp,
                        exchange: a.data.data.exchange,
                        _is_load: !1,
                        is_akey: !0
                    }), r.data.exchange[0]) {
                        var i = wx.createInnerAudioContext();
                        i.autoplay = !0, i.src = r.data.audio, i.onPlay(function() {
                            console.log("开始播放");
                        }), r.setData({
                            _exchange: !0
                        });
                    }
                } else r.setData({
                    _is_load: !1
                });
            }
        });
    },
    onHide: function() {},
    onNavigateTap: function(a) {
        wx.navigateTo({
            url: a.currentTarget.dataset.url
        });
    },
    onShareAppMessage: function() {
        var a = this, t = this.data.card_info.id + "," + this.data.card_info.openid;
        return {
            title: a.data.setup.fxtext + a.data.card_info.cardname + a.data.setup.fxtexth,
            desc: a.data.setup.fxtext + a.data.card_info.cardname + a.data.setup.fxtexth,
            path: "pages/card/info/info?card_id=" + t,
            success: function(a) {
                wx.showToast({
                    title: "转发成功",
                    icon: "success",
                    duration: 1e3,
                    mask: !0
                });
            },
            fail: function(a) {
                wx.showToast({
                    title: "转发失败",
                    icon: "error",
                    duration: 1e3,
                    mask: !0
                });
            }
        };
    },
    show_img: function(a) {
        wx.previewImage({
            current: a.currentTarget.dataset.src,
            urls: this.data.card_info.imgs
        });
    },
    show_weixin_img: function(a) {
        wx.previewImage({
            current: a.currentTarget.dataset.src,
            urls: [ a.currentTarget.dataset.src ]
        });
    },
    cardBJbind: function(a) {
        var t = this, e = a.target.dataset.id;
        wx.showActionSheet({
            itemList: [ "默认背景", "黄色背景", "红色背景", "淡绿背景", "彩虹背景", "黑色背景" ],
            success: function(a) {
                app.util.request({
                    url: "entry/wxapp/PostMyCardBj",
                    data: {
                        m: "bbyscm_card",
                        id: e,
                        bj: a.tapIndex
                    }
                }), t.setData({
                    bjid: a.tapIndex
                }), this.onPullDownRef(!0);
            },
            fail: function(a) {}
        });
    },
    pcard_template: function(a) {
        var t = this;
        if (1 == a.currentTarget.dataset.id) var e = 0; else if (0 == a.currentTarget.dataset.id) e = 1;
        var d = a.currentTarget.id;
        app.util.request({
            url: "entry/wxapp/PostPcard_template",
            data: {
                m: "bbyscm_card",
                id: d,
                ppcard_template: e
            },
            method: "POST",
            success: function(a) {
                0 == a.data.errno && t.setData({
                    card_template: e
                }), this.setData({
                    is_load_more: !0,
                    card_info: []
                }), this.onPullDownRef(!0);
            }
        });
    },
    pcard_imagp: function(a) {
        var t = this;
        if (1 == a.currentTarget.dataset.id) var e = 0; else if (0 == a.currentTarget.dataset.id) e = 1;
        var d = a.currentTarget.id;
        app.util.request({
            url: "entry/wxapp/PostPcard_imagp",
            data: {
                m: "bbyscm_card",
                id: d,
                imagp: e
            },
            method: "POST",
            success: function(a) {
                0 == a.data.errno && t.setData({
                    imagp: e
                }), this.setData({
                    is_load_more: !0,
                    card_info: []
                }), this.onPullDownRef(!0);
            }
        });
    },
    getcodes: function(a) {
        var d = !1, t = a.currentTarget.dataset.id;
        app.util.request({
            url: "entry/wxapp/GetCode",
            data: {
                m: "bbyscm_card",
                cardid: t,
                path: "pages/card/info/info?card_id=" + t
            },
            method: "POST",
            success: function(a) {
                if (0 == a.data.errno) {
                    var t = a.data.data;
                    wx.previewImage({
                        urls: [ t ]
                    }), setTimeout(function() {
                        d = !0, wx.hideToast();
                    }, 2e3);
                    var e = a.data.data;
                    wx.downloadFile({
                        url: e,
                        success: function(a) {
                            wx.saveImageToPhotosAlbum({
                                filePath: a.tempFilePath,
                                success: function(a) {},
                                fail: function(a) {
                                    "saveImageToPhotosAlbum:fail auth deny" === a.errMsg && wx.openSetting({
                                        success: function(a) {
                                            a.authSetting["scope.writePhotosAlbum"];
                                        }
                                    });
                                }
                            });
                        }
                    }), d = !0, wx.hideToast();
                }
            }
        }), setTimeout(function() {
            d || wx.showToast({
                title: "请稍后...",
                icon: "loading",
                duration: 2e3
            });
        }, 2e3);
    },
    onPullDownRefresh: function() {
        setTimeout(function() {
            wx.stopPullDownRefresh();
        }, 1e3);
    },
    open2: function() {
        this.setData({
            condition: !this.data.condition
        });
    },
    open: function(a) {
        var t = this, e = a.currentTarget.dataset.id;
        if (1 == t.data.videosetup.video_p && 0 == t.data.videosetup.video_pay) var d = [ "基本信息", "更多信息", "隐私设置", "上传图片", "上传视频" ]; else if (1 == t.data.videosetup.video_p && 1 == t.data.videosetup.video_pay && 0 < t.data.card_info.syts) d = [ "基本信息", "更多信息", "隐私设置", "上传图片", "上传视频" ]; else d = [ "基本信息", "更多信息", "隐私设置", "上传图片" ];
        wx.showActionSheet({
            itemList: d,
            success: function(a) {
                0 == a.tapIndex ? wx.navigateTo({
                    url: "../edit/card-edit?cardid=" + e
                }) : 1 == a.tapIndex ? wx.navigateTo({
                    url: "../edit_more/edit_more?cardid=" + e
                }) : 2 == a.tapIndex ? wx.navigateTo({
                    url: "../edit_privacy/edit_privacy?cardid=" + e
                }) : 3 == a.tapIndex ? wx.navigateTo({
                    url: "../edit_imgs/edit_imgs?cardid=" + e
                }) : 4 == a.tapIndex && wx.navigateTo({
                    url: "../edit_video/edit_video?cardid=" + e
                });
            },
            fail: function(a) {}
        });
    },
    show_share_bind: function() {
        var a = this;
        a.setData({
            is_show_share: !0
        }), setTimeout(function() {
            a.hide_share_bind();
        }, 2e3);
    },
    hide_share_bind: function() {
        this.setData({
            is_show_share: !1
        });
    },
    onNavigateTapa: function(a) {
        this.setData({
            fail: !1
        });
    },
    onNavigateTapb: function(a) {
        this.setData({
            fail: !1
        });
    },
    p_explain: function(a) {
        this.setData({
            explain: !this.data.explain
        });
    },
    cardEditmore: function(a) {
        var t = a.target.dataset.id;
        wx.navigateTo({
            url: "../edit_more/edit_more?cardid=" + t
        });
    },
    edit_imgs: function(a) {
        var t = a.target.dataset.id;
        wx.navigateTo({
            url: "../edit_imgs/edit_imgs?cardid=" + t
        });
    },
    cardEditBtn: function(a) {
        var t = a.target.dataset.id;
        wx.navigateTo({
            url: "../edit/card-edit?cardid=" + t
        });
    },
    play_video: function(a) {
        var t = a.currentTarget.id;
        wx.navigateTo({
            url: "../video/video?cardid=" + t
        });
    },
    collection: function(a) {
        wx.navigateTo({
            url: "../collection/collection"
        });
    },
    exchange: function(a) {
        wx.reLaunch({
            url: "../../user/exchange/exchange"
        });
    },
    call_phone_bind: function(a) {
        var t = a.currentTarget.id;
        "" != t && wx.makePhoneCall({
            phoneNumber: t
        });
    },
    onNavigateTap2: function(a) {
        JSON.stringify(a.detail.value);
        var t = a.detail.formId;
        a.currentTarget.id;
        app.util.request({
            url: "entry/wxapp/PostFormid",
            data: {
                m: "bbyscm_card",
                form_id: t
            }
        });
    },
    onNavigateTaptb: function(a) {
        var t = a.currentTarget.dataset.url, e = a.currentTarget.dataset.wx_appid, d = a.currentTarget.dataset.wx_path;
        e ? wx.navigateToMiniProgram({
            appId: e,
            path: d,
            extraData: {
                foo: "bar"
            },
            envVersion: "develop",
            success: function(a) {}
        }) : wx.navigateTo({
            url: "../info/info?card_id=" + t
        });
    },
    onUnload: function() {},
    onReachBottom: function() {}
});